# 正常添加任务
# @Time    : 2025/1/22 下午10:24
# @Author  : lh
# @Email   : lhhlhh822@peatlmail.com
# @File    : add_task_page.py
# @Software: PyCharm
import unittest
from time import sleep
from tools.tools import chrome
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class TestAddTask(BasePage):
    url = '/crm/index.php?m=task&a=add'
    zt_locator = (By.ID, 'subject')
    # 发送通知
    chancel_locator = (By.CSS_SELECTOR,
                       'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(2) > td:nth-child(4) > input[type=checkbox]:nth-child(1)')
    send_locator = (By.CSS_SELECTOR,
                    'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(2) > td:nth-child(4) > input[type=checkbox]:nth-child(2)')
    # 负责人
    fzr_locator = (By.ID, 'owner_name')
    # 勾选全部
    all_locator = (By.NAME, 'to_role_id[]')
    # 确定负责人
    first_fzr_locator = (By.CSS_SELECTOR, '#ta1 > span:nth-child(3) > input')
    last_fzr_locator = (By.CSS_SELECTOR, '#ta1 > span:nth-child(5) > input')
    sure_frz_locator = (By.CSS_SELECTOR, 'body > div:nth-child(12) > div.ui-dialog-buttonpane.ui-widget-content.ui'
                                         '-helper-clearfix > div > button:nth-child(1)')
    # 任务相关人
    xgr_locator = (By.ID, 'about_roles_name')
    last_xgr_locator = (By.CSS_SELECTOR, '#ta1 > span:nth-child(5) > input')
    sure_xgr_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]')

    # 下拉框
    choice_xlk_locator = (By.ID, 'select1')
    # 输入框
    choice_srk_locator = (By.ID, 'module_name')
    # 截至时间
    end_time_locator = (By.ID, 'due_date')
    ends_time_locator = (By.ID, 'due_date')

    # 状态
    status_locator = (By.CSS_SELECTOR,
                      'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(6) > '
                      'td:nth-child(2) > select')
    status_last_locator = (By.CSS_SELECTOR, 'body > div.container > div.row-fluid > div > form > table > tbody > '
                                            'tr:nth-child(6) > td:nth-child(2) > select > option:nth-child(4)')
    # 优先级
    priority_locator = (By.CSS_SELECTOR,
                        'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(6) > '
                        'td:nth-child(4) > select')
    priority_last_locator = (By.CSS_SELECTOR, 'body > div.container > div.row-fluid > div > form > table > tbody > '
                                              'tr:nth-child(6) > td:nth-child(4) > select > option:nth-child(3)')
    # 描述
    describe_locator = (By.XPATH, '/html/body')
    # 保存
    save_locator = (By.CSS_SELECTOR,
                    'body > div.container > div.row-fluid > div > form > table > tfoot > tr > td:nth-child(2) > '
                    'input:nth-child(1)')

    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')

    # 点击添加任务按钮
    # def add_task(self):
    #     self.find_element(self.add_user_locator).click()

    def input_zt(self, zt):
        self.find_element(self.zt_locator).send_keys(zt)  # 主题

    # 清空负责人在输入负责人
    # def input_fzr(self):
    #     self.find_element(self.fzr_locator).clear()
    #     self.find_element(self.fzr_locator).click()

    # 负责人

    def click_fzr(self):
        self.find_element(self.fzr_locator).clear()  # 清除负责人
        self.find_element(self.fzr_locator).click()
        self.find_element(self.first_fzr_locator).click()

    def lsat_click_fzr(self):
        self.find_element(self.fzr_locator).clear()  # 清除负责人
        self.find_element(self.fzr_locator).click()
        self.find_element(self.last_fzr_locator).click()

    def chancel_email(self):
        self.find_element(self.chancel_locator).click()

    def send_email(self):
        # self.find_element(self.send_locator).click()
        self.find_element(self.send_locator).click()

    def click_all_fzr(self):
        # 勾选负责
        self.find_element(self.all_locator).click()

    def click_sure_fzr(self):
        # 确定负责人
        self.find_element(self.sure_frz_locator).click()

    def input_xgr(self, xgr):
        self.find_element(self.xgr_locator).clear()
        self.find_element(self.xgr_locator).send_keys(xgr)

    def input_last_xgr(self):
        # self.find_element(self.xgr_locator).clear()
        self.find_element(self.xgr_locator).click()
        self.find_element(self.last_xgr_locator).click()

    def click_all_xgr(self):
        # 勾选相关人
        self.find_element(self.all_locator).click()

    def click_sure_xgr(self):
        # 确定相关人
        self.find_element(self.sure_xgr_locator).click()

    def drop_choice_xlk(self, xlk):
        xz = Select(self.find_element(self.choice_xlk_locator))
        xz.select_by_index(xlk)

    def last_choice_xlk(self, xlk):
        xz = Select(self.find_element(self.choice_xlk_locator))
        xz.select_by_index(xlk)

    #选择相关的输入框
    def input_choice_srk(self, srk):
        self.find_element(self.choice_srk_locator).send_keys(srk)

    def end_time(self, time):
        self.find_element(self.end_time_locator).send_keys(time)

    def ends_time(self):
        self.find_element(self.ends_time_locator).click()

    def status_task(self):
        self.find_element(self.status_locator).click()

    def status_last_task(self):
        self.find_element(self.status_last_locator).click()

    def priority_task(self):
        self.find_element(self.priority_locator).click()

    def priority_last_task(self):
        self.find_element(self.priority_last_locator).click()

    def describe_task(self, ms):
        self.find_element(self.describe_locator).send_keys(ms)

    def save_task(self):
        self.find_element(self.save_locator).click()

    #返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

    #返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text
